package com.example.dense_rack_server.controller;


import com.example.dense_rack_server.entityVo.MenuIndexDto;
import com.example.dense_rack_server.security.dto.JwtUserDto;
import com.example.dense_rack_server.service.MyMenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author  张彬 
 * @since 2025-03-03
 */
@RestController
@RequestMapping("/menu")
public class MyMenuController {

    @Resource
    private MyMenuService myMenuService;

    @GetMapping("/getlist")
    @ResponseBody
    @ApiOperation(value = "通过用户id获取菜单")
    public List<MenuIndexDto> getMenu() {
        JwtUserDto jwtUserDto = (JwtUserDto) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Integer userId = jwtUserDto.getMyUser().getUserId();
        return myMenuService.getMenu(userId);
    }

}
